#include "cardpanel.h"
#include <QMouseEvent>
#include<QPainter>
CardPanel::CardPanel(QWidget *parent)
    : QWidget{parent}
{
    m_isfront = true;
}

void CardPanel::setImage(QPixmap &front, QPixmap &back)
{
    m_front = front;
    m_back = back;

    setFixedSize(m_front.size());

    update();
}

QPixmap CardPanel::getImage()
{
    return m_front;
}

void CardPanel::setFrontsize(bool flag)
{
    m_isfront = flag;
}

bool CardPanel::getFrontsize()
{
    return m_isfront;
}

void CardPanel::setSelected(bool flag)
{
    m_isSelected = flag;
}

bool CardPanel::getSelected()
{
    return m_isSelected;
}

void CardPanel::setCard(Card &card)
{
    m_card = card;
}

Card CardPanel::getCard()
{
    return m_card;
}

void CardPanel::setOwner(Player *player)
{
    m_owner = player;
}

Player *CardPanel::getOwner()
{
    return m_owner;
}

void CardPanel::clicked()
{
    emit CardSelected(Qt::LeftButton);
}
void CardPanel::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter p(this);
    if(m_isfront)
    {
        p.drawPixmap(rect(),m_front);
    }
    else
    {
        p.drawPixmap(rect(),m_back);
    }
}
void CardPanel::mousePressEvent(QMouseEvent *event)
{
    emit CardSelected(event->button());

}

